package com.zxkj.commonpatrol.viewmodel;

import android.app.Application;

import androidx.annotation.NonNull;
import androidx.databinding.ObservableField;

import com.czy.basecommon.utils.base.BaseRepository;
import com.czy.basecommon.utils.base.BaseViewModel;
import com.czy.basecommon.utils.base.StateLiveData;
import com.zxkj.commonpatrol.model.post.PointNewEvent;
import com.zxkj.commonpatrol.model.response.PointInspectEvent;
import com.zxkj.commonpatrol.model.response.Questions;
import com.zxkj.commonpatrol.repoisity.AddEventRepoisity;

import java.time.chrono.IsoChronology;
import java.util.List;

public class AddEventViewModel extends BaseViewModel<AddEventRepoisity> {

public StateLiveData<List<String>> datas=new StateLiveData<>();
    public ObservableField<String> PointNo = new ObservableField<>("");
    public ObservableField<String> RSName = new ObservableField<>("");

    public ObservableField<String> PointType = new ObservableField<>("");

    public ObservableField<String> EName = new ObservableField<>("");

    public ObservableField<String> CName = new ObservableField<>("");

    public ObservableField<String> Loc = new ObservableField<>("");
    public StateLiveData<String> QuestsNo=new StateLiveData();
    public ObservableField<String> Time = new ObservableField<>("");
    public ObservableField<String> CPNB = new ObservableField<>("");
    public ObservableField<String> ZS = new ObservableField<>("");
    public ObservableField<String> ZL = new ObservableField<>("");
    public ObservableField<String> QuestList = new ObservableField<>("");

    public  StateLiveData<  List<Questions>> QuestEventList=new StateLiveData<>();
    public StateLiveData<Object>save=new StateLiveData<>();
    public StateLiveData<String>EventCode=new StateLiveData<>();
   public StateLiveData<List<PointInspectEvent.QuestionItem>> QuestListData=new StateLiveData<List<PointInspectEvent.QuestionItem>>();

    public AddEventViewModel(@NonNull Application application) {
        super(application);
    }



    public void  getQuestList(){
        mRepository.getQuestList(new BaseRepository.MyBaseDataCallBack<List<String>>() {
            @Override
            public void onDataSuccessCallBack(List<String> strings) {
                datas.postSuccess(strings);
            }

            @Override
            public void onDataFailCallBack(List<String> strings, List<String> t1) {

            }
        });
    }


    public void getEventDetail(String RouteInspectNo, String PointNos, String  EventNo){
        mRepository.GetPointInspectEventInfo(RouteInspectNo, PointNos, EventNo, new BaseRepository.MyBaseDataCallBack() {
            @Override
            public void onDataSuccessCallBack(Object o) {
                PointInspectEvent  bean=(PointInspectEvent)o;
                if (bean!=null){
                    EventCode.postSuccess(bean.EventCode);
                    QuestsNo.postSuccess(bean.QuestsNo);
                    RSName.set(bean.RSName);
                    EName.set(bean.EventName);
                    Loc.set(bean.getLocation());
                    QuestList.set(bean.getQuestsName());
                    if (bean.getQuesItems()!=null&&bean.getQuesItems().size()>0){
                        QuestListData.postSuccess(bean.getQuesItems());
                    }


                }

            }

            @Override
            public void onDataFailCallBack(Object o, Object t1) {

            }
        });
    }

    public void getEventList(String RouteInspectNo, String PointNo){
        mRepository.GetEventQuests(RouteInspectNo, PointNo, new BaseRepository.MyBaseDataCallBack() {
            @Override
            public void onDataSuccessCallBack(Object o) {
                List<Questions> bean=(List<Questions>)o;
                if (bean!=null&&bean.size()>0){
                    QuestEventList.postSuccess(bean);
                }
            }

            @Override
            public void onDataFailCallBack(Object o, Object t1) {

            }
        });

    }
    public void Save(String Code,String PointNo,String RouteInspectNo,String EventCode,int isAdd){
        PointNewEvent event=new PointNewEvent();
        event.setEventName(EName.get());
        event.setLocation(Loc.get());
        event.setQuestsNo(Code);
        event.setPointNo(PointNo);
        event.setRouteInspectNo(RouteInspectNo);
        event.setEventCode(EventCode);
        event.setIsAdd(isAdd);
        mRepository.Save(event, new BaseRepository.MyBaseDataCallBack() {
            @Override
            public void onDataSuccessCallBack(Object o) {
                if (o!=null){
                    save.postSuccess(o);
                }
            }

            @Override
            public void onDataFailCallBack(Object o, Object t1) {
                save.postFailure(404,(String)t1);
            }
        });
    }

}
